function loadPaikeData(data, startDateID, endDateID) {
	var uv, vv, pv, nu, nr, su;
	osArr = new Array();
	detailArr = new Array();
	dateArr = new Array();

	if (data.items.length > 0)
	{
		$(data.items).each(function(i, value){
			var myDate=new Date()

			year = value["year"];
			month = value["month"];
			day = value["day"];
			
			if (i == 0)
			{
				$("#"+startDateID).val(year+"/"+month+"/"+day);
			}

			myDate.setFullYear(year,month-1,day);
			dateArr.push(year + "/" + month + "/" + day);

			details = value["data"];
			$(details).each(function(l, dvalue){
				os = dvalue["os"];
				type = dvalue["type"];
				uv = dvalue["uv"]; //每日使用设备数
				pv = dvalue["pv"]; //页面访问量
				vv = dvalue["vv"]; //播放总量
				nu = dvalue["nu"]; //新增设备数
				nr = dvalue["nr"]; //注册用户数
				su = dvalue["su"]; //成功上传量

				if (typeof(dvalue["uv"])=="undefined")
					uv = 0;
				if (typeof(dvalue["vv"])=="undefined")
					vv = 0;
				if (typeof(dvalue["pv"])=="undefined")
					pv = 0;
				if (typeof(dvalue["nu"])=="undefined")
					nu = 0;
				if (typeof(dvalue["nr"])=="undefined")
					nr = 0;
				if (typeof(dvalue["su"])=="undefined")
					su = 0;			


				osi = in_array(os+" "+type, osArr);
				if(osi == -1) {
					osArr.push(os+" "+type);
					osi=osArr.length-1;
					detailArr[osi] = new Array();
					detailArr[osi][0] = new Array();
					detailArr[osi][1] = new Array();
					detailArr[osi][2] = new Array();
					detailArr[osi][3] = new Array();
					detailArr[osi][4] = new Array();
					detailArr[osi][5] = new Array();
					detailArr[osi][6] = new Array();
					detailArr[osi][7] = new Array();

				}

				if(dateArr.length-detailArr[osi][0].length > 1) {
					var size = dateArr.length-detailArr[osi][0].length;
					for(l=1; l<size; l++) {
						detailArr[osi][0].push(0);
						detailArr[osi][1].push(0);
						detailArr[osi][2].push(0);
						detailArr[osi][3].push(0);
						detailArr[osi][4].push(0);
						detailArr[osi][5].push(0);
						detailArr[osi][6].push(0);
						detailArr[osi][7].push(0);

					}
				}

				detailArr[osi][0].push(vv);
				detailArr[osi][1].push(uv);
				detailArr[osi][2].push(pv);
				detailArr[osi][3].push(nu);
				detailArr[osi][4].push(nr);
				detailArr[osi][5].push(su);
				if (uv == 0 || vv == 0)
					detailArr[osi][7].push(0);
				else
					detailArr[osi][7].push(parseFloat((vv/uv).toFixed(2)));

			});
		});		
		$("#"+endDateID).val(year+"/"+month+"/"+day);
	}
	else {
		alert("选择的时间区间内无数据");	
		$("#"+startDateID).val("");
		$("#"+endDateID).val("");
	}
}


function loadPaikeOSComp(data) {
	//读取累计使用设备数
	var tuURL = "http://10.103.13.15:8000/client/paikeTotalUser";
	if ($("#PaikeOSCompEndDate").val() != "")
	{
		tuURL = tuURL + "?endDate=" + $("#PaikeOSCompEndDate").val();
	}

	userTotalDiv = "PaikeOSCompPie";
	$.ajax({
		type: "GET",
		url: tuURL,
		cache: true,
		dataType : "jsonp",
		jsonnp: "callback",
		success: onLoadTotalUser
	});

	$(".PaikeOSCompChartTab").hide();
	$("#PaikeOSCompPieTab").show();	
	$(".bitem").removeClass("selbitem");
	loadPaikeData(data, "PaikeOSCompStartDate", "PaikeOSCompEndDate");
	if (data.items.length > 0)
	{
		$(".tab-content").show();	
		changePaikeOSCompValueType(1);
//		genTable("PaikeOSCompTable", osArr, dateArr, detailArr, 1);
//		genLineChart("PaikeOSCompLine", "PaikeUV趋势图", dateArr, osArr, detailArr, typeValue, $("#PaikeOSCompStartDate").val().replace(/\//g, "-") + " 至 " + $("#PaikeOSCompEndDate").val().replace(/\//g, "-"));
//		genPieChart("PaikeOSCompPie", "Paike累计UV百分比图", osArr, detailArr, typeValue, $("#PaikeOSCompStartDate").val().replace(/\//g, "-") + " 至 " + $("#PaikeOSCompEndDate").val().replace(/\//g, "-"));	
//		genAreaChart("PaikeOSCompArea", "PaikeUV趋势图", dateArr, osArr, detailArr, typeValue, $("#PaikeOSCompStartDate").val().replace(/\//g, "-") + " 至 " + $("#PaikeOSCompEndDate").val().replace(/\//g, "-"));
	}
	else {
		$(".tab-content").hide();	
	}


	jQuery('#body-wrapper').hideLoading();
}


//tab切换
function changePaikeOSCompValueType(typeValue) {
	var title = "";
	if (typeValue == 0)
		title = "VV";
	else if(typeValue == 1)
		title = "UV";
	else if(typeValue == 2)
		title = "PV";
	else if (typeValue == 3)
		title = "NU";
	else if (typeValue == 4)
		title = "NR";
	else if (typeValue == 5)
		title = "SU";
	else if (typeValue == 6)
		title = "TU";
	else if (typeValue == 7)
		title = "VV/UV";

	if (typeValue == 6)
	{
		genTotalUserPieChart("PaikeOSCompPie", "Paike" + title +"百分比图", "截止至" + $("#PaikeOSCompEndDate").val().replace(/\//g, "-"));
		$(".PaikeOSCompChartTab").hide();
		$("#PaikeOSCompPieTab").show();
		$("#PaikeOSCompArea").hide();
		changeChartType('PaikeOSComp', 'Pie');

	} 
	else if(typeValue == 7) {
		genTable("PaikeOSCompTable", osArr, dateArr, detailArr, typeValue);
		genLineChart("PaikeOSCompLine",  "Paike" + title +"趋势图", dateArr, osArr, detailArr, typeValue, $("#PaikeOSCompStartDate").val().replace(/\//g, "-") + " 至 " + $("#PaikeOSCompEndDate").val().replace(/\//g, "-"));		
		$(".PaikeOSCompChartTab").show();
		$("#PaikeOSCompLine").show();
		$("#PaikeOSCompArea").hide();
		changeChartType('PaikeOSComp', 'Line', typeValue)
		$("#PaikeOSCompPieTab").hide();
		$("#PaikeOSCompAllTab").hide();
	}	
	else {
		genTable("PaikeOSCompTable", osArr, dateArr, detailArr, typeValue);
		genLineChart("PaikeOSCompLine", "Paike" + title +"趋势图", dateArr, osArr, detailArr, typeValue, $("#PaikeOSCompStartDate").val().replace(/\//g, "-") + " 至 " + $("#PaikeOSCompEndDate").val().replace(/\//g, "-"));
		genPieChart("PaikeOSCompPie", "Paike累计" + title +"百分比图", osArr, detailArr, typeValue, $("#PaikeOSCompStartDate").val().replace(/\//g, "-") + " 至 " + $("#PaikeOSCompEndDate").val().replace(/\//g, "-"));	
		genAreaChart("PaikeOSCompArea", "Paike" + title +"趋势图", dateArr, osArr, detailArr, typeValue, $("#PaikeOSCompStartDate").val().replace(/\//g, "-") + " 至 " + $("#PaikeOSCompEndDate").val().replace(/\//g, "-"));
		$(".PaikeOSCompChartTab").show();
		$("#PaikeOSCompArea").show();
		changeChartType('PaikeOSComp', 'Pie')

	}
	$(".bitem").removeClass("selbitem");
	$("#paikeOSCompTab"+typeValue).addClass("selbitem");			
	
}

